﻿using System;
using System.IO;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using Maticsoft.BLL;
using Maticsoft.Model;

namespace FineUI.Examples
{
    public partial class admin_updatecourse : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("~/login.aspx");
            }
            BindGrid();

        }

        public DataSet BindGrid()
        {
            Maticsoft.BLL.Course currentCourse = new Maticsoft.BLL.Course();
            DataSet RtDate = currentCourse.GetAllList();

            DataView view1 = RtDate.Tables[0].DefaultView;
            Grid1.DataSource = view1;
            Grid1.DataBind();
            return RtDate;


        }

        protected void CourseDelete(string currentC_Id)
        {
            Maticsoft.BLL.Course Course = new Maticsoft.BLL.Course();
            Course.Delete(currentC_Id);
        }


        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {//删除
            if (e.CommandName == "ActionDelete")
            {
                int key = e.RowIndex;
                string CurrentC_Id = BindGrid().Tables[0].Rows[key]["C_Id"].ToString();
                CourseDelete(CurrentC_Id);
                Response.Redirect("~/admin_updatecourse.aspx");
            }
            //修改
            if (e.CommandName == "ActionUpdate")
            {
                int key = e.RowIndex;
                string CurrentC_Id = BindGrid().Tables[0].Rows[key]["C_Id"].ToString();
                string CurrentC_Name = BindGrid().Tables[0].Rows[key]["C_Name"].ToString();
                string CurrentC_Credit = BindGrid().Tables[0].Rows[key]["C_Credit"].ToString();

                Session["C_Id"] = CurrentC_Id;
                Session["C_Name"] = CurrentC_Name;
                Session["C_Credit"] = CurrentC_Credit;
                CourseDelete(CurrentC_Id);

                Response.Redirect("~/admin_readdcourse.aspx");
            }



        }


        protected void search_btn_Click(object sender, EventArgs e)
        {

        }


        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid();

        }

    }
}